package com.yanxibao.controller;

import com.yanxibao.bean.Blog;
import com.yanxibao.common.Result;
import com.yanxibao.dto.BlogDTO;
import com.yanxibao.dto.PageQueryDTO;
import com.yanxibao.service.BlogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 推文控制器
 *
 * @author kongke
 * @date 2023/11/19
 */
@Api(tags = "推文接口")
@CrossOrigin
@RequestMapping("/blog")
@RestController
public class BlogController {

    @Resource
    private BlogService blogService;

//    增，删，改（点赞，点击量），查

    /**
     * 添加推文
     * 不用传时间
     */
    @ApiOperation("新增推文")
    @PostMapping("/add")
    public Result<Blog> addBlog(@RequestBody Blog blog){
        return blogService.addBlog(blog);
    }

    @ApiOperation("删除推文")
    @DeleteMapping("/delete")
    public Result<Boolean> deleteBlog(@RequestParam("id") Integer id){
        return blogService.deleteBlog(id);
    }

    @ApiOperation("更新推文")
    @PutMapping("/update")
    public Result<Blog> updateBlog(@RequestBody Blog blog){
        return blogService.updateBlog(blog);
    }

    @ApiOperation("查询推文")
    @GetMapping("/query")
    public Result<PageQueryDTO<BlogDTO>> queryBlog(@RequestParam("userId") String userId){
        return blogService.queryBlog(userId);
    }

    @ApiOperation("根据id查询推文")
    @GetMapping("/getById/{blogId}")
    public Result<Blog> queryById(@PathVariable("blogId") Integer blogId){
        return blogService.queryById(blogId);
    }

    @ApiOperation("点赞推文")
    @GetMapping("/likeBlog/{blogId}")
    public Result<Integer> likeBlog(@PathVariable("blogId") Integer blogId){
        return blogService.likeBlog(blogId);
    }

    @ApiOperation("是否已赞")
    @GetMapping("/isLike/{blogId}")
    public Result<Boolean> isLike(@PathVariable("blogId") Integer blogId){
        return blogService.isLike(blogId);
    }

}
